package com.aididi.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Auther: zx.xu
 * @Description:
 */
@Service
@Slf4j
public class TestService {

    @SentinelResource(value="sayHello",blockHandler ="handleException")
    public String sayHello(String name){
        return "hello:"+name;
    }

    /**
     * 自定义异常策略
     * 返回值和参数要跟目标函数一样，参数可以追加BlockException
     */
    public String handleException(String name,BlockException exception){
        log.info("flow exception{}"+name,exception.getClass().getCanonicalName());
        return "达到阈值了,不要再访问了!";
    }

}
